//
// Created by wrj on 2024/8/3.
//

#ifndef HTTP_CLIENT_HTTP_H
#define HTTP_CLIENT_HTTP_H
#define MAX_REQUEST_SIZE 1024  //处理请求时
#define MAX_RESPONSE_SIZE 1024 //处理响应时
typedef  struct {
    short  post;            //端口
    char hostname[64];     //主机名字
    char res_path[256];   //资源定位符
    char filename[64];     //文件名
}taskInfo;
typedef struct {
    char *header;
    ssize_t pos;			// 待插入的位置索引
    ssize_t capacity;
}HeaderBuffer;
int parser_task(const char *url, taskInfo *task);
taskInfo *createTask();
void releaseTask(taskInfo *task);
int init_socket(taskInfo *task);
HeaderBuffer *createHeaderBuffer(int size);
void add_request_start_line(HeaderBuffer *buffer, const char *method, const char *url);
void add_request_header(HeaderBuffer *buffer, const char *key, const char *value);
void add_request_end_line(HeaderBuffer *buffer);
HeaderBuffer *build_request_header(taskInfo *task);
void releaseHeaderBuffer(HeaderBuffer *buffer);
ssize_t send_data_bytes(int sock_fd, const void *_data, ssize_t len);
HeaderBuffer *rcv_response_header(int sock_fd);
int get_status(HeaderBuffer *response);
void get_content_size(HeaderBuffer *response, const char *key, size_t *len);
size_t init_file(HeaderBuffer *response_header, int fd);
size_t receive_bytes(int sock_fd, int fd, size_t cnt_size);
#endif //HTTP_CLIENT_HTTP_H
